package top.lixunda.ecommerce.server.good.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.common.validate.XumValid;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.good.api.entity.db.EnshrineStoreDO;
import top.lixunda.ecommerce.server.good.api.entity.dto.EnshrineStoreQueryDTO;
import top.lixunda.ecommerce.server.business.api.entity.dto.PageDTO;
import top.lixunda.ecommerce.server.good.api.entity.vo.EnshrineStoreVO;
import top.lixunda.ecommerce.server.good.api.controller.IEnshrineStoreController;
import top.lixunda.ecommerce.server.good.service.IEnshrineStoreService;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 店铺收藏
 * </p>
 *
 * @author Xumda
 * @version time:2020/1/7 16:25
 */
@Slf4j
@RestController
public class EnshrineStoreController extends BaseController
        implements IEnshrineStoreController {

    private final IEnshrineStoreService enshrineStoreService;

    @Autowired
    public EnshrineStoreController(IEnshrineStoreService enshrineStoreService) {
        this.enshrineStoreService = enshrineStoreService;
    }

    @Override
    public MessageObject<Boolean> addEnshrineStore(Integer id) {
        enshrineStoreService.addEnshrineStore(Collections.singletonList(id));
        return getSuccessMessageObject("收藏店铺成功", true);
    }

    @Override
    public MessageObject<Integer> addEnshrineStores(List<Integer> ids) {
        int size = enshrineStoreService.addEnshrineStore(ids);
        return getSuccessMessageObject("收藏店铺成功", size);
    }

    @Override
    public MessageObject<Boolean> removeEnshrineStore(Integer id) {
        enshrineStoreService.removeEnshrineStore(Collections.singletonList(id));
        return getSuccessMessageObject("收藏店铺成功", true);
    }

    @Override
    public MessageObject<Integer> removeEnshrineStores(List<Integer> ids) {
        int size = enshrineStoreService.removeEnshrineStore(ids);
        return getSuccessMessageObject("收藏店铺成功", size);
    }

    @Override
    public MessageObject<List<EnshrineStoreVO>> queryAllEnshrineStores() {
        List<EnshrineStoreDO> list = enshrineStoreService.queryAllEnshrineStore();
        return getSuccessMessageObject("获取店铺收藏数据成功",
                EnshrineStoreVO.fromEnshrineStoreDO(list));
    }

    @Override
    public MessageObject<List<EnshrineStoreVO>> queryEnshrineStoresWrapper(@XumValid EnshrineStoreQueryDTO enshrineGoodQueryDTO) {
        List<EnshrineStoreDO> list = enshrineStoreService.queryEnshrineStoreWrapper(enshrineGoodQueryDTO);
        return getSuccessMessageObject("获取店铺收藏数据成功",
                EnshrineStoreVO.fromEnshrineStoreDO(list));
    }

    @Override
    public MessageObject<IPage<EnshrineStoreVO>> queryEnshrineStoresPage(
            @XumValid PageDTO<EnshrineStoreDO, ?> pageDTO) {
        IPage<EnshrineStoreDO> page = enshrineStoreService.queryEnshrineStorePage(pageDTO);
        return getSuccessMessageObject("获取店铺收藏数据成功",
                pageConvert(page, EnshrineStoreVO::fromEnshrineStoreDO));
    }

    @Override
    public MessageObject<IPage<EnshrineStoreVO>> queryEnshrineStoresPageWrapper(
            @XumValid PageDTO<EnshrineStoreDO, EnshrineStoreQueryDTO> pageDTO) {
        IPage<EnshrineStoreDO> page = enshrineStoreService.queryEnshrineStorePageWrapper(pageDTO);
        return getSuccessMessageObject("获取店铺收藏数据成功",
                pageConvert(page, EnshrineStoreVO::fromEnshrineStoreDO));
    }

    @Override
    public MessageObject<EnshrineStoreVO> queryById(Integer id) {
        return getSuccessMessageObject("获取数据成功",
                EnshrineStoreVO.fromEnshrineStoreDO(enshrineStoreService.queryById(id)));
    }

    @Override
    public MessageObject<List<EnshrineStoreVO>> queryByIds(List<Integer> ids) {
        return getSuccessMessageObject("获取数据成功",
                EnshrineStoreVO.fromEnshrineStoreDO(enshrineStoreService.queryByIds(ids)));
    }

}
